/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/06/28
*/
#ifndef __EDUI_SDL_WINDOW_H__
#define __EDUI_SDL_WINDOW_H__

#include "SDL.h"
#include "edui/interface/IWindow.h"
#include "edui/utilities/String.h"
#include "Render.h"

EDUI_NAMESPACE_BEGIN

class Window : public IWindow
{
public:
    static Window* GetInterface();
    virtual void Release();
    static Window* ToWindow(IWindow* wnd);
#ifdef EDUI_TEST_NEW_DELETE
    static int m_newdeleteNum;
    static int _GetNewDeleteNum();
#endif
protected:
    Window();
    virtual ~Window();
public:
    virtual bool Create(const char* name, const char* title, int x, int y, int w, int h, Uint32 flags, int index = -1);
    virtual bool Create(const char* name, SDL_Window* sdlwnd, int index = -1);
    
    virtual const char* GetName() const;
    virtual bool SetName(const char* name);
    virtual Uint32 GetID() const;

    virtual Uint32 GetFlags() const;

    virtual const char* GetTitle() const;
    virtual void SetTitle(const char* title);

    virtual void SetIcon(ISurface* icon);
    virtual ISurface* GetIcon();

    virtual bool  SetCaptionRect(const Rect* caption);
    virtual Rect  GetCaptionRect() const;
    virtual bool  SetSizeBox(const Rect1* rcBox);
    virtual Rect1 GetSizeBox() const;

    virtual int   GetWidth() const;
    virtual int   GetHeight() const;
    virtual Point GetPos() const;
    virtual void  SetPos(int x, int y);
    virtual Size  GetSize() const;
    virtual void  SetSize(int w, int h);
    virtual Rect  GetRect() const;
    virtual void  SetRect(int x, int y, int w, int h);
    virtual Size  GetMaxSize() const;
    virtual void  SetMaxSize(int w, int h);
    virtual Size  GetMinSize() const;
    virtual void  SetMinSize(int w, int h);

    virtual void* SetUserData(const char* name, void* data);//set user data to use,return prev data.
    virtual void* GetUserData(const char* name) const;

    virtual bool SetFullScreen(WndFullScreen flags);

    virtual void MaxWindow() const;
    virtual void MinWindow() const;
    virtual void RestoreWindow() const;
    virtual void ShowWindow() const;
    virtual void HideWindow() const;

    virtual bool IsEnabled() const;
    virtual void SetEnabled(bool enabled);

    virtual bool IsOK();
    virtual void Destroy();

    virtual IRender* GetRender();

    virtual IFont* GetFont();//get default font
    virtual bool SetFont(IFont* font);//set default font
    
    virtual bool SetInputFocus();
    virtual void StartTextInput();
    virtual bool IsTextInputActive();
    virtual void StopTextInput();
    virtual void SetTextInputRect(Rect* rc);

    virtual bool SetParent(IWindow* wnd);
    virtual IWindow* GetParent() const;

    //0.0-1.0
    virtual bool SetOpacity(float opacity);
    //-1:err;
    virtual float GetOpacity();

public:
    SDL_Window* GetSDLWindow() const;
protected:
    virtual void onCreate();
    virtual void onDestroy();
protected:
    SDL_Window* m_wnd;
    Uint32 m_wndID;
    String m_name;
    edui::Render m_render;

    Rect m_rcCaption;
    Rect1 m_rcBox;

    IFont* m_font;
    IWindow* m_parent;

    bool m_bEnabled;

    ISurface* m_icon;
};

EDUI_NAMESPACE_END

#endif